/* 双向线性链表 */

#include <stdio.h>
#include "double_link_list.h"

/* 测试用例 */
int main (void) {

        printf("建立双向链表\n");
	LIST* list = list_create ();


        /*尾部插入*/
        printf("插入数据\n");
	list_append (list, 10);
	list_append (list, 30);
	list_append (list, 50);
        /*在第一个位置之后插入20*/
	list_insert (list, 1, 20);
	list_insert (list, 3, 40);

        getchar();
        /*正向遍历*/
        printf("正向遍历链表\n");
        list_forward_traverse(list);

        getchar();
        printf("再次插入数据\n");
	list_append (list, 41);
	list_append (list, 41);

        getchar();
        printf("正向遍历链表\n");
        list_forward_traverse(list);

        /*删除*/
        getchar();
        printf("删除节点\n");
	list_erase (list, 1);
	list_remove (list, 41);

        /*反向遍历*/
        getchar();
        printf("反向遍历\n");
        list_reverse_traverse(list);

        /*随机访问*/
        getchar();
        printf("随机访问\n");
	size_t pos, size = list_size (list);
	for (pos = 0; pos < size; ++pos)
		printf ("%d ", *list_at (list, pos));
	printf ("\n");
        
        /*删除*/
        getchar();
        printf("删除链表\n");
	list_clear (list);
	printf ("%d, %d\n", list_empty (list), list_size (list));

	list_destroy (list);
	return 0;
}
